package com.hcxny.chat

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class MessageAdapter(private val msgList: List<Msg>) :
    RecyclerView.Adapter<MessageAdapter.ViewHolder>() {

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.adapter_message, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val msg = msgList.get(position)
        holder.itemView.findViewById<TextView>(R.id.userView).text = msg.user
        holder.itemView.findViewById<TextView>(R.id.contentView).text = msg.content
    }

    override fun getItemCount(): Int {
        return msgList.size
    }
}

data class Msg(val content: String, val user: String)